package ua.yandex.skipasssystem.skipass.validators;

import ua.yandex.skipasssystem.skipass.NumberOfDaysInterface;
import ua.yandex.skipasssystem.skipass.SkiPass;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class NumberOfDaysSkiPassValidator extends
        WithDaysOfWorkingSkiPassValidator {

    private NumberOfDaysSkiPassValidator() {

    }

    public static NumberOfDaysSkiPassValidator getValidator() {
        return ValidatorHolder.VALIDATOR_HOLDER;
    }

    @Override
    public boolean validate(SkiPass skiPass,
                            LocalDateTime dateTime) {
        boolean isCorrectDateAndActive =
                super.validate(skiPass, dateTime);
        LocalDate date = dateTime.toLocalDate();
        return isCorrectDateAndActive && isWorkAtDay(skiPass, dateTime)
                && ((NumberOfDaysInterface) skiPass).ifCanAddDay(date);
    }

    public static class ValidatorHolder {
        public static final NumberOfDaysSkiPassValidator VALIDATOR_HOLDER =
                new NumberOfDaysSkiPassValidator();
    }
}

